<?php
/**
 * 产品管理
 *
 */
namespace Admin\Controller;
use Think\Controller;
use Common\Controller\BaseController;

class ProductLineController extends BaseController {
	/*列表*/
	public function index(){
		$res = array('rcode'=>1,'data'=>NULL, 'msg'=> 'OK');
		$psize = I('get.psize', $this->m_psize,'intval');
		$name = I('get.name','','trim');

		if( !$psize )
			$psize = $this->m_psize;
		else if( $psize > 20 )
			$psize = $this->m_psize;

		$MProductLine = D("product_line");
		$MQY = M("qy");
		$wheres = array();
		$wheres['name'] = array('like', '%'.$name.'%');
		$wheres['is_deleted'] = array('neq', 1);

		$cnt = $MProductLine->where( $wheres )->count();
		$Page = new \Common\ORG\Page( $cnt, $psize );
		$productline_list = $MProductLine->field("product_line.*")
						->where($wheres)
			            ->limit($Page->firstRow.','.$Page->listRows )
			            ->select();
		if($productline_list){
			for ($i=0; $i < count($productline_list); $i++) { 
				$map[$i] = array();
				$map[$i]['product_line_code'] = array('eq',$productline_list[$i]['product_line_code']);
				$qyDate[$i] = $MQY->field('*')->where($map[$i])->select();
				$productline_list[$i]['qyDate'] = $qyDate[$i];
			}
		}	
		if( $productline_list ){
  			$res['rcode'] = 1;
  			$res['msg'] = "OK";
  			$res['data'] = $productline_list;
  			$res['pall'] =  $Page->getTotalPages();
  			$res['p'] = $Page->nowPage;
		}else{
	       	$res['rcode'] = 2;
			$res['msg'] = "产品线信息列表为空";
		}
		e_json( $res );
	}

}
